from django.test import TestCase
from django.test.client import Client

"""
Testira stranu promene passworda
"""
class ProfilePasswordChangeTestCase(TestCase):
    
    def setUp(self):
        pass

    def runTest(self):
        c = Client()
        c.login(username='kokan', password='123')
        
        response = c.get("/mdcs/profile/password_change/")
        self.failIf(response == None)
        self.failIf(response.context == None)
        self.failUnlessEqual(len(response.context), 2)
        self.failIf(response.context[0]["form"] == None)
        self.assertEqual(len(response.context[0]["messages"]), 0)

        # promeni password
        response = c.post("/mdcs/profile/password_change/",
            {"old_password": "123", "new_password1": "1", "new_password2": "1"}, follow=True)
        self.failUnless(len(response.redirect_chain), 1)
        self.failIf(response == None)
        self.failIf(response.context == None)
        self.failUnlessEqual(len(response.context), 2)
        self.failIf(response.context[0]["form"] == None)
        self.assertEqual(len(response.context[0]["messages"]), 1)
        
        # probaj logovanje
        self.assertFalse(c.login(username='kokan', password='123'))
        self.assertTrue(c.login(username='kokan', password='1'))